/* eslint-disable no-unused-vars */
import request from '@/utils/request'
import CryptoJS from 'crypto-js'

// AES加密
export function encrypt(encStr) {
  // 字符串 encStr = 'lc'
  const key = CryptoJS.enc.Utf8.parse('1234123412ABCDEF') // 十六位十六进制数作为密钥
  const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234123412') // 十六位十六进制数作为密钥偏移量
  const srcs = CryptoJS.enc.Utf8.parse(encStr)
  const encrypted = CryptoJS.AES.encrypt(srcs, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  }).toString()
  return encrypted
}

// AES解密
export function decrypt(encrypted) {
  // 一个字符串的密文
  const key = CryptoJS.enc.Utf8.parse('1234123412ABCDEF') // 十六位十六进制数作为密钥
  var decrypt = CryptoJS.AES.decrypt(encrypted, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  })
  const decryptedStr = CryptoJS.enc.Utf8.stringify(decrypt).toString()
  return decryptedStr
}
